﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ys.Base.Common
{
    /// <summary>
    /// long数据拓展
    /// </summary>
  public static  class LongExtension
    {
        /// <summary>
        /// 将毫秒时间戳转换为普通时间
        /// </summary>
        /// <param name="timestamp">毫秒级别的时间戳</param>
        /// <returns></returns>
        public static DateTime ToDateTimeMilliseconds(this long timestamp)
        {
            System.DateTime time = System.DateTime.MinValue;
            DateTime startTime = new DateTime(1970, 1, 1, 0, 0, 0);
            time = startTime.AddMilliseconds(timestamp).Add(TimeZoneInfo.Local.BaseUtcOffset);
            return time;
        }
        /// <summary>
        ///  将秒级别时间戳转换为普通时间
        /// </summary>
        /// <param name="timestamp">秒级别的时间戳</param>
        /// <returns></returns>
        public static DateTime ToDateTimeSecoders(this long timestamp)
        {
            DateTime time = System.DateTime.MinValue;
          
            DateTime startTime =new DateTime(1970,1,1,0,0,0);
            time = startTime.AddSeconds(timestamp).Add(TimeZoneInfo.Local.BaseUtcOffset);
            return time;
        }
        /// <summary>
        /// 讲标准时间戳(秒级)转换为时间格式
        /// </summary>
        /// <param name="timestamp"></param>
        /// <returns></returns>

        public static DateTime ToDateTime(this long timestamp)
        {
            return ToDataTime(timestamp);
        }

        /// <summary>
        /// 将标准时间戳(秒级)转换为时间格式
        /// </summary>
        /// <param name="timestamp"></param>
        /// <returns></returns>
        public static DateTime ToDataTime(this long timestamp)
        {
            return ToDateTimeSecoders(timestamp);
        }


        /// <summary>
        /// 向上整除
        /// 1.当num能被divideBy整除时,结果即为num/divideBy;
        /// 2.当num不能被divideBy整除时,结果为num/divideBy + 1;
        /// </summary>
        /// <param name="num">被除数,大于或者等于0</param>
        /// <param name="divideBy">除数,大于0</param>
        /// <returns>向上整除结果</returns>
        public static long CeilingDivide(this long num, long divideBy)
        {
            if (num < 0 || divideBy <= 0)
            {
                return 0;
            }

            return (num + divideBy - 1) / divideBy;

        }

    }
}
